﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Windows;
using System.ComponentModel;
using System.Windows.Forms;

namespace IVS.Calculator
{
    class ApplicationController
    {
        #region ------------------------------ CONSTRUCTION ------------------------------

        /// <summary>
        /// Creates instance of ApplicationController.
        /// </summary>
        public ApplicationController ()
        { }

        #endregion

        #region ------------------------------ FIELDS ------------------------------

        MainWindowView _mainWindow;

        #endregion

        #region ------------------------------ PROPERTIES ------------------------------

        #endregion

        #region ------------------------------ PUBLIC METHODS ------------------------------

        /// <summary>
        /// Starts application and shows main window.
        /// Returns FALSE and shows error message box in case of error, returns TRUE otherwise.
        /// </summary>
        /// <returns></returns>
        public bool StartApplication ()
        {
            _mainWindow = new MainWindowView();
            _mainWindow.ImportPresenter(new MainWindowPresenter());

            try
            {
                Application.Run(_mainWindow);
            }
            catch
            {
                string msg = "Unexpected error occured.\nApplication will be closed.";
                MessageBox.Show(msg, "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                return false;
            }
            return true;
        }

        #endregion

        #region ------------------------------ PRIVATE METHODS ------------------------------

        #endregion

        #region ------------------------------ EVENTS ------------------------------

        #endregion
    }
}
